import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

 public class CookieServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		
		 PrintWriter out = res.getWriter();
	       
	        Cookie userCookie = new Cookie("username", req.getParameter("username"));
			Cookie passwordCookie = new Cookie("password", req.getParameter("password")); 
	        res.addCookie(userCookie);
			res.addCookie(passwordCookie);
	        
	        // then write the data of the response
	        String username = req.getParameter("username");
	       
	        if ((username != null) && (username.length() > 0)) {
	            out.println("<h2>Hello, " + username + "!</h2>");
	        }
	       
	        String password = req.getParameter("password");
	       
	        if ((password != null) && (password.length() > 0)) {
	            out.println("<h2>Your password is " + password + "!</h2>");
	        }
	}
}